﻿using Microsoft.EntityFrameworkCore;

namespace SmartCommunity.Models
{
    public partial class SCDBContext
    {
        // 全局配置
        protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
        {
            //configurationBuilder.Properties<string>().AreUnicode(false);
        }

        /// <summary>
        /// 覆盖自动生成的数据库配置
        /// </summary>
#pragma warning disable CA1822 // 将成员标记为 static
        partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
#pragma warning restore CA1822 // 将成员标记为 static
        {
            // 自动加载关联数据
            //modelBuilder.Entity<UserEntity>().Navigation(a => a.Dept).AutoInclude();

            // 批量覆盖配置
            //foreach (var entityType in modelBuilder.Model.GetEntityTypes())
            //{
            //    foreach (var propertyInfo in entityType.ClrType.GetProperties())
            //    {
            //        if (propertyInfo.Name.ToLower() == "remark" || propertyInfo.Name.ToLower() == "description" || propertyInfo.Name.EndsWith("name"))
            //        {
            //            entityType.FindProperty(propertyInfo.Name)?.SetIsUnicode(true);
            //        }
            //    }
            //}
        }
    }
}
